#!/bin/bash
function check_user()
{
    local line
    line=`grep "$1" /etc/passwd -nRw | cut -d ":" -f 1`
    echo $line
}
function get_user_info()
{
    local info
    info=`head -$1 /etc/passwd | tail -1 | cut -d ":" -f 1,3,4`
    echo $info
}
read -p "input username > " name

if [ -z "$name" ]
then
    echo "input error ,try again"
    exit 1
else
    line=`check_user $name`
    if [ -z "$line" ]
    then
        echo "input username not exists"
        exit 1
    else
        info=`get_user_info $line`
        echo -n "chek user info:"
        echo $info
    fi
fi
